//处理用户登录逻辑
const db =require("../lib/db")
function userLogin(username,userpwd){
//1.用户不存在
//2.密码错误
//3.登录成功
return new Promise((resolve,reject)=>{
let sql="select * from user where userName='"+ username +"'";
db.querySql(sql).then(data=>{
    console.log(data)
    if(data.length==0){
        //用户不存在
        console.log("用户不存在")
        resolve(501)
    }else{
        if(data[0].userPassword == userpwd){
            //登录成功
            console.log("登录成功")
            resolve(data[0])
        }else{
            //密码错误
            console.log("密码错误")
            resolve(502)
        }
    }
   })
 })
}
//导出
module.exports=userLogin